package com.tox.service.impl;

import java.util.List;

import com.tox.bean.Weibo;
import com.tox.dao.JavatoxWeiboDAO;
import com.tox.dao.pojo.JavatoxUserLevel;
import com.tox.dao.pojo.JavatoxWeibo;
import com.tox.service.WeiboService;
import com.tox.util.FriendTime;

public class WeiboServiceImpl implements WeiboService {
	
	private JavatoxWeiboDAO weiboDAO;
	

	public void setWeiboDAO(JavatoxWeiboDAO weiboDAO) {
		this.weiboDAO = weiboDAO;
	}

	@Override
	public List<JavatoxWeibo> weiboList() {
		// TODO Auto-generated method stub
		List<JavatoxWeibo> list=weiboDAO.weiboList();
		List<JavatoxUserLevel> levels=weiboDAO.getLevels();
		
		for (JavatoxWeibo item : list) {
			for (JavatoxUserLevel level : levels) {
				if(item.getUser().getScore()>=level.getStart()&&item.getUser().getScore()<=level.getEnd()){
					item.getUser().setLevel(level.getName());
					break;
				}
//				System.out.println(111);
			}
		}
		return list;
	}

	@Override
	public JavatoxWeibo weiboPublic(Weibo weibo) {
		// TODO Auto-generated method stub
		JavatoxWeibo weiboSend=weiboDAO.weiboPublic(weibo);
		List<JavatoxUserLevel> levels=weiboDAO.getLevels();
		weiboSend.setCreateTime(FriendTime.stamp2Firendtime(weiboSend.getCreateTime()));
		for (JavatoxUserLevel level : levels) {
			if(weiboSend.getUser().getScore()>=level.getStart()&&weiboSend.getUser().getScore()<=level.getEnd()){
				weiboSend.getUser().setLevel(level.getName());
				break;
			}
		}
		return weiboSend;
	}

	@Override
	public boolean weiboSupport(int uid, int weiboId) {
		boolean result= weiboDAO.weiboSupport(uid, weiboId);
		// TODO Auto-generated method stub
		return result;
	}
}
